Skip to content

fix: infer HTTP for URL-only Codex MCP imports#85

Open
brushax wants to merge 1 commit intoSaladDay:mainfrom
brushax:fix/codex-mcp-import-url-infer-http
Open

fix: infer HTTP for URL-only Codex MCP imports#85
brushax wants to merge 1 commit intoSaladDay:mainfrom
brushax:fix/codex-mcp-import-url-infer-http

Conversation

@brushax
Copy link
Copy Markdown

@brushax brushax commented Apr 2, 2026

Summary

  • fix Codex MCP import type inference when type is omitted but url is present
  • preserve current behavior for explicit type and stdio entries
  • add regression coverage for URL-only Codex entries with custom fields (e.g. bearer_token_env_var)

Root cause

import_from_codex() defaulted missing type to stdio unconditionally. Valid Codex URL-based entries without an explicit type were therefore validated as stdio and rejected due to missing command.

Fix

In Codex import, infer http when:

  • type is absent
  • url exists and is non-empty

Otherwise keep the existing fallback to stdio.

Validation

  • cargo fmt --manifest-path src-tauri/Cargo.toml --all --check
  • cargo test --test import_export_sync import_from_codex --manifest-path src-tauri/Cargo.toml
  • cargo test --test import_export_sync --manifest-path src-tauri/Cargo.toml

Closes #84

Copilot AI review requested due to automatic review settings April 2, 2026 00:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Codex MCP import so URL-only entries (missing type but with url) are treated as HTTP servers instead of defaulting to stdio, addressing import failures for valid remote MCP servers.

Changes:

  • Update import_from_codex() to infer type = "http" when url is present and non-empty and type is omitted.
  • Add a regression test covering URL-only Codex MCP entries, including preservation of custom fields like bearer_token_env_var.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src-tauri/src/mcp.rs Adjust Codex import type inference to treat URL-only entries as HTTP.
src-tauri/tests/import_export_sync.rs Add regression test ensuring URL-only Codex entries import as HTTP and keep custom fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 445 to 455
let typ = entry_tbl
.get("type")
.and_then(|v| v.as_str())
.or_else(|| {
entry_tbl
.get("url")
.and_then(|v| v.as_str())
.filter(|url| !url.trim().is_empty())
.map(|_| "http")
})
.unwrap_or("stdio");
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new inference uses .get("type").and_then(|v| v.as_str()).or_else(...), which will infer http not only when type is absent, but also when type is present but not a string (e.g. type = 1). That diverges from the PR intent (“type is absent”) and can silently import misconfigured entries. Consider checking entry_tbl.contains_key("type") first (or filtering out non-string/empty values as a validation error) so inference only happens when the key is truly missing.

Suggested change
let typ = entry_tbl
.get("type")
.and_then(|v| v.as_str())
.or_else(|| {
entry_tbl
.get("url")
.and_then(|v| v.as_str())
.filter(|url| !url.trim().is_empty())
.map(|_| "http")
})
.unwrap_or("stdio");
let typ = if entry_tbl.contains_key("type") {
// 如果显式提供了 type,则仅使用该字段(缺失或类型不匹配时回退到 stdio),
// 不再根据 url 推断为 http,避免静默掩盖配置错误。
entry_tbl
.get("type")
.and_then(|v| v.as_str())
.unwrap_or("stdio")
} else {
// 仅在完全省略 type 时,才允许通过非空 url 推断为 http。
entry_tbl
.get("url")
.and_then(|v| v.as_str())
.filter(|url| !url.trim().is_empty())
.map(|_| "http")
.unwrap_or("stdio")
};

Copilot uses AI. Check for mistakes.
Comment on lines +443 to 455
// Codex 的远程 MCP 可以只写 `url`,不显式提供 `type`。
// 这种情况下应按 HTTP 服务器导入,而不是回退到 stdio。
let typ = entry_tbl
.get("type")
.and_then(|v| v.as_str())
.or_else(|| {
entry_tbl
.get("url")
.and_then(|v| v.as_str())
.filter(|url| !url.trim().is_empty())
.map(|_| "http")
})
.unwrap_or("stdio");
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: if typ ends up unknown (including the case where type is an empty string), the later match typ { _ => { ... return changed; } } returns from the import_servers_tbl closure, which stops processing remaining servers in the same table. Since the intent is to “skip” invalid items, this should likely continue the per-item loop instead, and/or filter out empty/whitespace type values up front to avoid hitting the unknown-type path.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex MCP import misclassifies URL-based servers as stdio

2 participants